<?php

    spl_autoload_register(function($className){
        if (substr($_SERVER['DOCUMENT_ROOT'],-1) === "\\" || substr($_SERVER['DOCUMENT_ROOT'],-1)==="/" ){
            $document_root=substr($_SERVER['DOCUMENT_ROOT'],0,-1);
        }else{
            $document_root=$_SERVER['DOCUMENT_ROOT'];
        }
        
        $pos=array("/lib/","/ctrl/");
        foreach ($pos as $value)
        {
            $filepos=$document_root.$value.strtolower($className).'.php';
            if (file_exists($filepos))
            {
                require($filepos);
                return;
            }
        }
    });

    date_default_timezone_set(Util::config('timezone'));
    
    if (Util::config('dev')){
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods:*');
        header('Access-control-Allow-Headers:*');
        header('Access-Control-Max-Age:2592000');
    }

    Router::exe(Req::method(),Req::uri());
    // Res::json(Router::exe(Req::method(),Req::uri()));